package com.suning.sawp.service.util;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author Wuxiao
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class BeanUtil {

    /**
     * <b>对象对应属性拷贝 </b><br>
     * 
     * @param destObj 目标对象
     * @param origObj 源对象
     */
    private static Logger logger =LoggerFactory.getLogger(BeanUtil.class);
    
    public static void copyProperties(Object destObj, Object origObj) {
        try {
            if (null != origObj && null != destObj) {
               BeanUtils.copyProperties(destObj, origObj);
            }
        } catch (IllegalAccessException e) {  
            logger.warn("copyProperties", e);
        } catch (InvocationTargetException e) {
            logger.warn("copyProperties", e);
        } 
    }
    
    @SuppressWarnings("unchecked")
    public static Map<String, Object> describe(Object obj) {
        Map<String, Object> param = null;
            try {
                param = BeanUtils.describe(obj);
                param.remove("class");
            } catch (IllegalAccessException e) {
                logger.error("", e);
            } catch (InvocationTargetException e) {
                logger.error("", e);
            } catch (NoSuchMethodException e) {
                logger.error("", e);
            }
        return param;
    }
}
